package com.yc.config;


import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Mono;

//@Configuration
public class RateLimiterConfig {

    @Bean  //该 Bean 名必须与配置中 key-resolver: "#{@ipKeyResolver}" 保持一致
    public KeyResolver ipKeyResolver() {
        return exchange -> {
            String ip = exchange.getRequest()
                    .getRemoteAddress()
                    .getAddress()
                    .getHostAddress();
            System.out.println("限流 Key = " + ip);
            return Mono.just(ip);  // 按 IP 地址限流

        };
    }
}
